package org.x.usermod.service.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.x.usermod.dto.CreateRoleUserDTO;
import org.x.usermod.service.ISysRoleUserService;
import org.x.usermod.entity.SysRoleUser;
import org.x.usermod.mapper.SysRoleUserMapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.x.usermod.vo.RoleVo;

@Service
public class SysRoleUserServiceImpl extends ServiceImpl<SysRoleUserMapper, SysRoleUser> implements ISysRoleUserService {

    @Autowired
    private SysRoleUserMapper sysRoleUserMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int createRoleUser(CreateRoleUserDTO createRoleUserDTO) {
        SysRoleUser sysRoleUser = new SysRoleUser();
        sysRoleUser.setUserId(createRoleUserDTO.getUserId());
        sysRoleUser.setRoleId(createRoleUserDTO.getRoleId());
        sysRoleUser.setCreatedTime(createRoleUserDTO.getCreatedTime());
        return sysRoleUserMapper.insert(sysRoleUser);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int removeByUserId(Long userId) {
         QueryWrapper queryWrapper = QueryWrapper.create()
                 .where(SysRoleUser::getUserId).eq(userId);
         return getMapper().deleteByQuery(queryWrapper);
    }

    @Override
    public Page<RoleVo> RoleList(CreateRoleUserDTO createRoleUserDTO) {
        return null;
    }

}
